<?php
namespace Kxdrmobile\Model;
use Think\Model\ViewModel;
class UserGiftsViewModel extends ViewModel {
    public $viewFields = array(
     'user_gifts'=>array('_table'=>"sm_kxdr_user_gifts",'id','sid','eid','egid','epid','guess_id','user_id','gift_id','gift_name','gift_pic_url','player_id','send_time','is_picup','picup_time','gift_num','gift_type','get_type','user_nick','gift_name','gift_pic_url','_type'=>'LEFT'),
     'event'=>array('_table'=>"sm_kxdr_events",'_on'=>'user_gifts.eid=event.id', 'game_id','time_out','time_out_type','title'=>'event_title','description','pic_url','logo_url','sid','tag','need_seeds','multi_yes','multi_no','gifting_time','edit_time','assign_id','h5url','version','_type'=>'LEFT'),
     'event_gifts'=>array('_table'=>"sm_kxdr_event_gifts",'_on'=>'user_gifts.egid=event_gifts.id','event_player_id','quantity','quantity_install','score_diff','get_type','add_time','getting_json','probability','type','level','level_name','lottery_times','name','promoid','tagid','pic_url','advance','every_minute','range_time_start','range_time_end','every_lotts','advance_quantity','ext_rule','medal_id','medal_name','medal_pic','rule_medal_id','rule_medal_name','rule_medal_pic','medal_quant','collect_items','order_items','cart_items','show_title','show_content','jifen','payment','pay_time_start','pay_time_end','_type'=>'LEFT'),
     'guess'=>array('_table'=>"sm_kxdr_user_guess",'_on'=>'user_gifts.guess_id=guess.id','epid','guess_type','guess_value','mixed_nick','guess_time','guess_value_difference','_type'=>'LEFT'),
     'event_players'=>array('_table'=>"sm_kxdr_event_players",'_on'=>'user_gifts.epid=event_players.id', 'think_type', 'think_type_sign', 'think_type_way','title'=>'player_title','player_descrip','game_data_json','extend','target_data','target_data_sign','_type'=>'LEFT'),
     );
    public function showMyGifts(){
		unset($this->viewFields["event"]);
		unset($this->viewFields["event_gifts"]);
		$where["sid"]=$this->sid;
		$where["user_id"]=$this->uid;
		$where["gift_id"]=$this->gift_id;
		$gifts = $this->where($where)->order("`id` DESC")->limit($this->limit)->getField("id,guess_time,guess_value_difference,think_type_way,player_title,gift_name,gift_pic_url");
		$GFT_TYPE = C("GFT_TYPE");
		foreach($gifts as $k=>$gift){
			foreach($GFT_TYPE as $tp){
				if($gift["gift_type"] == $tp["id"]){
					$gifts[$k]["gift_type"] = $tp["name"];
				}
			}
			foreach(C("KXDR_THINK_WAY") as $way){
				if($gift["think_type_way"]==$way["id"]){
					$gifts[$k]["think_type_way_name"]=$way["name"];break;
				}
			}
			switch($gifts[$k]["score_diff"]){
				case 0 :
					$gifts[$k]["score_diff_txt"].="预测成功";
				break;
				case -1 :
					$gifts[$k]["score_diff_txt"].="没猜中";
				break;
				default:
					$gifts[$k]["score_diff_txt"].="差".$gifts[$k]["score_diff"]."分预测成功";
				break;
			}
			$gifts[$k]["score_diff_txt"].="，获得该奖品";
		}
		
		return $gifts;
	}
	public function getAllCount(){
		unset($this->viewFields["event"]);
		unset($this->viewFields["event_gifts"]);
		unset($this->viewFields["guess"]);
		unset($this->viewFields["event_players"]);
		$where["sid"]=$this->sid;
		$where["user_id"]=$this->uid;
		$where["gift_id"]=$this->gift_id;
		return $this->where($where)->count();
	}
 }
 